#ifndef __MESSAGE_H
#define __MESSAGE_H

#include "../serialize/decode.h"
#include "../driver/log_uart.h"

namespace conn {


class Message {

public:
    Message(const uint8_t *buf = nullptr, uint8_t len = 0)
        : m_buf(buf), m_len(len) {}

    uint8_t action() const { return m_buf[0]; }
    uint8_t u8arg0() const { return m_buf[1]; }

    void print_hex() const {
		using namespace driver;
        logUart.printf("msg:");
        for (uint8_t i = 0; i < m_len; i ++) {
            logUart.printf("%02x ", m_buf[i]);
        }
        logUart.printf("\r\n");
    }

    template <typename... Ts> utils::Error parse_req(Ts &...ts) const {
        return serialize::decode_all(m_buf + 1, m_len - 3, ts...);
    }

private:
    const uint8_t *m_buf;
    uint8_t m_len;
};

} // namespace conn

#endif
